﻿using System;
using System.Collections.Generic;
using mshtml;
using WebHacker;
using PosHacker.Form;
using PosHacker.Utility;
using System.Xml;
using System.Web;
using PosHacker.PosException;
using Utility_Log;

namespace PosHacker
{
   

    public enum PosLink
    {
        //link
        LOGIN,

        MENU,
        MENU_REF,
        
        MARKABLE_LIST,
        MARKCONFIG,
        
        PARTIALSELECTQUESTION,
        PCPARTIALLIST,

        SELECTMARKABLEQUESTIONS,
        PREPAREPCMARKING,

        //para link
        APP_ID_LOGIN,
        APP_ID_LOGINFORCHECK,

        //
        CHANGE_PASSWORD,

    }

    public delegate void PosDelegate();

    public class POSHacker
    {
        private WebTools phWebTools;

        private Dictionary<PosLink, string> httpLink;

        private mshtml.HTMLDocument pHTMLDocument;

        private FormLogin posFormLogin;
        private FormChangePassword posFormChangePassword;

        private string Menu_VIEWSTATE;

        private string MainFrameSrc;
        private string TopFrameSrc;
        private string testKouseiId;

        private static POSHacker _instance;


        public static POSHacker GetInstance(string pUser, string pPwd)
        {
            //if (POSHacker._instance == null)
               _instance = new POSHacker(pUser, pPwd);

            return _instance;
            
        }

        public static POSHacker GetInstance()
        {
            if (POSHacker._instance == null)
                throw new SystemException("POSHacker is null!");

            return POSHacker._instance;
        }

        private POSHacker(string pUser, string pPwd)
        {
            //http
            phWebTools = new WebTools();
            
            //Login
            this.posFormLogin = new FormLogin();
            this.posFormLogin.txtUserID = pUser;
            this.posFormLogin.txtPassword = pPwd;

            //Links
            httpLink = new Dictionary<PosLink, string>();
            httpLink.Add(PosLink.LOGIN, @"http://pos.yotsuyaotsuka.net/SSO2/Examiner/SSOLogin/SSOLogin.aspx");
            httpLink.Add(PosLink.MENU, @"http://pos.yotsuyaotsuka.net/SSO2/Examiner/SSOMenu/SSOMenu.aspx");
            httpLink.Add(PosLink.MENU_REF, @"http://pos.yotsuyaotsuka.net/SSO2/Examiner/SSOMenu/");
            httpLink.Add(PosLink.MARKABLE_LIST, @"http://pos.toshin.com/MarkingSystemWeb/selectMarkableSheets.do");
            httpLink.Add(PosLink.MARKCONFIG, @"http://pos.toshin.com/MarkingSystemWeb/markConfig.do");
            
            httpLink.Add(PosLink.SELECTMARKABLEQUESTIONS, @"http://pos.toshin.com/MarkingSystemWeb/selectMarkableQuestions.do");
            httpLink.Add(PosLink.PCPARTIALLIST, @"http://pos.toshin.com/MarkingSystemWeb/pcPartialList.do");


            //PC Partial Marking
            httpLink.Add(PosLink.PARTIALSELECTQUESTION, @"http://pos.toshin.com/MarkingSystemWeb/pcPartialSelectQuestion.do");
            //PC Marking
            httpLink.Add(PosLink.PREPAREPCMARKING, @"http://pos.toshin.com/MarkingSystemWeb/preparePcMarking.do");

            //採点
            httpLink.Add(PosLink.APP_ID_LOGIN, @"JAVA|http://pos.toshin.com/MarkingSystemWeb/login.do?businessArea=1&id=10501|undefined");
            //採点検証
            httpLink.Add(PosLink.APP_ID_LOGINFORCHECK, @"JAVA|http://pos.toshin.com/MarkingSystemWeb/loginForCheck.do?businessArea=1&id=10501|undefined");
            //Changepassword
            httpLink.Add(PosLink.CHANGE_PASSWORD,@"http://pos.yotsuyaotsuka.net/SSO2/Examiner/SSOMenu/ChangePassword.aspx");

        }

        public void Login()
        {
            this.ActionLoginPre();
            this.ActionLoginPre_GetLoginViewStatus();
            this.ActionLogin();
            this.ActionLogin_GetMenuViewStatus();
        }

        public void Login(string pUser, string pPwd)
        {
            this.ActionLoginPre();
            this.ActionLoginPre_GetLoginViewStatus();
            this.ActionLogin(pUser,pPwd);
            this.ActionLogin_GetMenuViewStatus();
        }

        public bool ChangPassword(string presentPwd,string newPwd)
        {
            this.posFormChangePassword = new FormChangePassword();

            this.OpenChangePasswordPage();

            this.posFormChangePassword.txtPresentPWD = presentPwd;
            this.posFormChangePassword.txtNewPWD = newPwd;
            this.posFormChangePassword.txtNewPWDConfirm = newPwd;
            return this.ChangePassword();

        }

        private void OpenChangePasswordPage()
        {
            this.pHTMLDocument
                = this.phWebTools.HttpRequest(
                                    this.httpLink[PosLink.CHANGE_PASSWORD],
                                    new RequestHeaders());

            this.posFormChangePassword.__VIEWSTATE = 
                this.GetElementById("__VIEWSTATE", "value");

            this.posFormChangePassword.__EVENTVALIDATION =
                this.GetElementById("__EVENTVALIDATION", "value");
        }

        private bool ChangePassword()
        {
            this.pHTMLDocument
                = this.phWebTools.SubmitFormData(this.httpLink[PosLink.CHANGE_PASSWORD], this.posFormChangePassword.ToString());

            if(this.pHTMLDocument.scripts.length == 3)
            {
                var _script =
                    this.pHTMLDocument.scripts.item(2) as HTMLScriptElement;
                if (_script.innerHTML.Contains("window.location.href ='SSOMenu.aspx'"))
                    return true;

            }
            return false;
        }


        //採点
        public Dictionary<string,string> GetTestNames() { 
            
            this.ActionMenuMark(this.httpLink[PosLink.APP_ID_LOGIN]);
            Log4netManager.Instance.Logs.Error("E1");
            Log4netManager.Instance.Logs.Error(this.pHTMLDocument.body.outerHTML);

            this.ActionMenuMark_GetFrameSrc();
            Log4netManager.Instance.Logs.Error("E2");
            this.ActionMainFrame();
            Log4netManager.Instance.Logs.Error("E3");
            return 
                this.ActionMainFrame_GetMarkCourseNames(); ;
        }

        public List<FormSetCourse> GetMarkableList(string pTestExecId)
        {
            this.ActionSubjectCourse(pTestExecId);

            return
            this.ActionSubjectCourse_Get();

        }

        public bool SetTestCourseInfo(FormSetCourse fsc)
        {

            this.ActionSetTestCourseInfo(fsc);

            return
            this.CheckSetCourse();
        }

        public List<FormSetScoringNo> GetMarkableQuestionsList()
        {

            //open
            FormGetMarkableQuestions vFGML = this.ActionOpenPartialMarking();


            //list
            List<FormSetScoringNo> listFSSN = null;
            if (vFGML != null)
            {
                listFSSN =
                this.ActionGetMarkableQuestions(vFGML);//缺少件数信息
            }

            return listFSSN;
        }




        //採点検証
        public Dictionary<string, string>[] GetInfoLoginForCheck()
        {

            this.ActionMenuMark(this.httpLink[PosLink.APP_ID_LOGINFORCHECK]);
            this.ActionMenuMark_GetFrameSrc();
            this.ActionMainFrame();

            //Dictionary<string, string> testNames =
            //this.ActionMainFrame_GetInfoForCheck();

            return
                this.ActionMainFrame_GetInfoForCheck();
        }

        public void StepTwo()
        {

            this.ActionMenuMark(this.httpLink[PosLink.APP_ID_LOGIN]);
            this.ActionMenuMark_GetFrameSrc();
            this.ActionMainFrame();
            Dictionary<string,string> dd=
            this.ActionMainFrame_GetMarkCourseNames();
            //
            //
            this.ActionSubjectCourse("25097");
            List<FormSetCourse> lFsc =
            this.ActionSubjectCourse_Get();
            //
            FormSetCourse fsc = lFsc[23];
            fsc.testExecId = "25097";
            fsc.reservationPriority = "1";
            //

            this.ActionSetTestCourseInfo(fsc);

            //PC Marking
            //
            //PC Partial Marking
            FormGetMarkableQuestions vFGML = this.ActionOpenPartialMarking();
            List<FormSetScoringNo> listFSSN = null;
            if (vFGML != null) {
                listFSSN =
                this.ActionGetMarkableQuestions(vFGML);//缺少件数信息
            }


            FormSetScoringNo vFSSN = listFSSN[7];
            //
            vFSSN.testKouseiId = "";//?
            vFSSN.numberOfSet = "50";
            vFSSN.mouseMarker = "2";
            vFSSN.testKouseiId = this.testKouseiId;
            //

            this.ActionPartialQuestionsLoad(vFSSN);
            this.ParsePartialXML();
            //this.OpenPartialSelectQuestion();

            return;

            //this.GetSubjectCourse();
            //this.action
            //
            //Dictionary<string, string> vTestNames =
            //this.Menu();

            //
            //Dictionary<string, string>.KeyCollection.Enumerator ke =
            //vTestNames.Keys.GetEnumerator();
            //int i = 0;

            //while (ke.MoveNext())
            //{
            //    if (i == 3)
            //        break;
            //    i++;
            //}

            //select change form submit
            //POST
            //http://pos.toshin.com/MarkingSystemWeb/markConfig.do
            //penId:
            //testExecId:25097
            //subjectCourseTestId:
            //subjectCourseNm:
            //pageNum:
            //pageNumInt:0
            //reservationPriority:1

            //this.SetTestCourseInfo1();

            //
            //Console.WriteLine(ke.Current);
            //FormSetCourse fsc =
            //this.GetSubjectCourse(ke.Current);

            //if (fsc == null)
            //    return;

            //fsc.testExecId = ke.Current;
            //fsc.reservationPriority = "1";//Unmarked


            ////fsc.reservationPriority = "2";//Marked partially
            //this.SetTestCourseInfo(fsc);

            //
            // /MarkingSystemWeb/preparePcMarking.do
            // /MarkingSystemWeb/pcPartialSelectQuestion.do


        }

		/// <summary>
		/// 获取PCmarking页面URL
		/// </summary>
		/// <returns></returns>
		public string GetPCMarkingActionLink()
		{
			return this.httpLink[PosLink.PREPAREPCMARKING] + "?"
									+ "time="
									+ POSUtility.GetJSTime(); ;
		}

		/// 获取採点検証页面URL
		/// </summary>
		/// <returns></returns>
		public string GetInconsistentMarkActionLink()
		{
			this.ActionMenuMark(this.httpLink[PosLink.APP_ID_LOGINFORCHECK]);
			this.ActionMenuMark_GetFrameSrc();
			//this.ActionMainFrame();

			return MainFrameSrc;
			//return this.httpLink[PosLink.APP_ID_LOGINFORCHECK] ;
		}
        private void ActionLoginPre() {
            //Pre-Load
            this.pHTMLDocument
                = this.phWebTools.HttpRequest(
                    this.httpLink[PosLink.LOGIN],
                        new RequestHeaders());     
        }

        private void ActionLoginPre_GetLoginViewStatus(){



            
            //IHTMLElement ihe;
            //GET VIEWSTATUS
            //ihe = this.pHTMLDocument.getElementById("__VIEWSTATE");
            //this.posFormLogin.__VIEWSTATE = ihe.getAttribute("value").ToString();

            this.posFormLogin.__VIEWSTATE =
            this.GetElementById("__VIEWSTATE", "value");


            //GET __EVENTVALIDATION
            //ihe = this.pHTMLDocument.getElementById("__EVENTVALIDATION");
            //this.posFormLogin.__EVENTVALIDATION = ihe.getAttribute("value").ToString();

            this.posFormLogin.__EVENTVALIDATION =
                this.GetElementById("__EVENTVALIDATION", "value");

        }

        private void ActionLogin()
        {

            //Login
            this.pHTMLDocument
                = this.phWebTools.SubmitFormData(this.httpLink[PosLink.LOGIN], this.posFormLogin.ToString());

            //Check
            this.CheckLogin();

        }

        private void ActionLogin(string pUser, string pPwd)
        {

            this.posFormLogin.txtUserID = pUser;
            this.posFormLogin.txtPassword = pPwd;

            //Login
            this.pHTMLDocument
                = this.phWebTools.SubmitFormData(this.httpLink[PosLink.LOGIN], this.posFormLogin.ToString());

            //Check
            this.CheckLogin();

        }

        private void ActionLogin_GetMenuViewStatus()
        {
            //IHTMLElement ihe;
            //result
            //ihe = this.pHTMLDocument.getElementById("__VIEWSTATE");
            //this.Menu_VIEWSTATE = ihe.getAttribute("value").ToString(); 
            this.Menu_VIEWSTATE =
            this.GetElementById("__VIEWSTATE", "value");
        }

        private void ActionMenuMark(string app_Id)
        {

            HttpRequestDictionary vFormParas = new HttpRequestDictionary();

            vFormParas.Add("__EVENTTARGET", "LinkButton1");
            vFormParas.Add("__EVENTARGUMENT", "");
            vFormParas.Add("__VIEWSTATE", this.Menu_VIEWSTATE);
            vFormParas.Add("app_Id", app_Id);
            vFormParas.Add("SSOMenuLinksControl1$hdselectedtab", "");

            this.pHTMLDocument =
                this.phWebTools.SubmitFormData(this.httpLink[PosLink.MENU], vFormParas.ToString());
            Log4netManager.Instance.Logs.Error(app_Id);
            Log4netManager.Instance.Logs.Error(this.httpLink[PosLink.MENU]);
            Log4netManager.Instance.Logs.Error(vFormParas.ToString());
        }

        private void ActionMenuMark_GetFrameSrc() {

            IHTMLElement ihe;
            IHTMLElementCollection ihec = this.pHTMLDocument.getElementsByTagName("FRAME");

            ihe = (IHTMLElement)ihec.item(0);//TOPFRAME
            if (ihe != null)
                this.TopFrameSrc = ihe.getAttribute("src").ToString();
            
            ihe = (IHTMLElement)ihec.item(1);//MAINFRAME
            if (ihe != null)
                this.MainFrameSrc= ihe.getAttribute("src").ToString();
        }
        private void ActionTopFrame() {
            this.pHTMLDocument =
                this.phWebTools.HttpRequest(httpLink[PosLink.MENU_REF] + this.TopFrameSrc,
                    new RequestHeaders());
        }

        private void ActionMainFrame()
        {
            this.pHTMLDocument =
            this.phWebTools.HttpRequest(this.MainFrameSrc,
                new RequestHeaders());
        }
        private string ActionMainFrameText()
        {
            //this.pHTMLDocument =
            //return this.phWebTools.HttpRequest_Text(this.MainFrameSrc,
            //    new RequestHeaders());
            return this.MainFrameSrc;
        }

        private Dictionary<string, string> ActionMainFrame_GetMarkCourseNames()
        {
            if (this.pHTMLDocument == null)
                return null;
           
            IHTMLElementCollection
            ihec = this.pHTMLDocument.getElementsByTagName("select");
            Log4netManager.Instance.Logs.Error("E4");
            HTMLSelectElement hse = (HTMLSelectElement)ihec.item(0);

            ihec = hse.getElementsByTagName("option");
            HTMLOptionElement hoe;

            Dictionary<string, string> resMenuTestItems = new Dictionary<string, string>();
            Log4netManager.Instance.Logs.Error("E5");
            for (int i = 0; i < ihec.length; i++)
            {

                hoe = (HTMLOptionElement)ihec.item(i);

                resMenuTestItems.Add(hoe.text, hoe.value);
                Console.WriteLine(hoe.value);
                Console.WriteLine(hoe.text);
            }
            Log4netManager.Instance.Logs.Error("E6");
            return resMenuTestItems;
        
        }

        private Dictionary<string, string>[] ActionMainFrame_GetInfoForCheck()
        {
            Dictionary<string, string>[] resArry = new Dictionary<string, string>[2];

            IHTMLElementCollection
            ihec = this.pHTMLDocument.getElementsByTagName("select");

            //name="testExecId"
            HTMLSelectElement hse = (HTMLSelectElement)ihec.item(0);

            ihec = hse.getElementsByTagName("option");
            HTMLOptionElement hoe;

            Dictionary<string, string> resMenuTestItems = new Dictionary<string, string>();

            for (int i = 0; i < ihec.length; i++)
            {

                hoe = (HTMLOptionElement)ihec.item(i);

                resMenuTestItems.Add(hoe.text, hoe.value);
                Console.WriteLine(hoe.value);
                Console.WriteLine(hoe.text);
            }

            resArry[0] = resMenuTestItems;

            //name="kyokaKamokuId"
            hse = (HTMLSelectElement)ihec.item(1);

            ihec = hse.getElementsByTagName("option");

            resMenuTestItems = new Dictionary<string, string>();

            for (int i = 0; i < ihec.length; i++)
            {

                hoe = (HTMLOptionElement)ihec.item(i);

                resMenuTestItems.Add(hoe.text, hoe.value);
                Console.WriteLine(hoe.value);
                Console.WriteLine(hoe.text);
            }

            resArry[1] = resMenuTestItems;

            return resArry;

        }

        private void ActionSubjectCourse(string pTestExecId)
        {
            string requestLink = this.httpLink[PosLink.MARKABLE_LIST]
                                    + "?"
                                    + "testExecId="
                                    + pTestExecId
                                    + "&"
                                    + "time="
                                    + POSUtility.GetJSTime();

            //DateTime.Now
            this.pHTMLDocument =
            this.phWebTools.HttpRequest(requestLink, new RequestHeaders());

        }

        private List<FormSetCourse> ActionSubjectCourse_Get()
        {

            IHTMLElementCollection ihec =
            this.pHTMLDocument.getElementsByTagName("input");

            List<FormSetCourse> fscList = new List<FormSetCourse>();

            IHTMLElement ihe;
            string tmpSheetNum = "";
            for (int i = 0; i < ihec.length; i++)
            {

                ihe = (IHTMLElement)ihec.item(i);
                Console.WriteLine(ihe.outerHTML);
                Console.WriteLine(ihe.parentElement.parentElement.document);
                
                

                if (ihe.outerHTML.Contains("onclick=\"setSheet("))
                {
                    //+sheetnum
                    IHTMLElementCollection tmpCollect =
                    (IHTMLElementCollection)ihe.parentElement.parentElement.children;
                    IHTMLElement tmpElement;
                    if (tmpCollect.length > 1)
                    {
                        tmpElement = (IHTMLElement)tmpCollect.item(2);
                        tmpSheetNum =
                        tmpElement.innerText;
                    }
                    //-sheetnum

                    fscList.Add(new FormSetCourse(ihe.outerHTML, tmpSheetNum));
                }

            }

            return fscList;
        }

        private void ActionSetTestCourseInfo(FormSetCourse fsc)
        {

            this.pHTMLDocument =
                this.phWebTools.SubmitFormData(this.httpLink[PosLink.MARKCONFIG], fsc.ToString());

        }
        public string _OpenPartialMarking_Link { get; set; }
        private FormGetMarkableQuestions ActionOpenPartialMarking() {
            string tmpLink = this.httpLink[PosLink.PARTIALSELECTQUESTION]
                                + "?time="
                                + POSUtility.GetJSTime();
            this._OpenPartialMarking_Link = tmpLink;

            this.pHTMLDocument =
            this.phWebTools.HttpRequest(tmpLink, new RequestHeaders());

            IHTMLElementCollection ihec;

            //
            ihec = 
            this.pHTMLDocument.getElementsByName("testKouseiId");

            if (ihec.length == 1)
            {
                this.testKouseiId =
                ((IHTMLElement)ihec.item(0)).getAttribute("value").ToString();
            }
            //

            FormGetMarkableQuestions fgml = new FormGetMarkableQuestions();

            ihec =
            this.pHTMLDocument.getElementsByTagName("form");
            HTMLFormElement hfe = (HTMLFormElement)ihec.item(0);

            IHTMLElement ihe =
            (IHTMLElement)this.pHTMLDocument.getElementById("selectMarkableQuestions");

            if (ihe != null && ihe.outerHTML.Contains("onclick=\"selectMarkableList("))
            {
                return new FormGetMarkableQuestions(ihe.outerHTML);
            }

            return null;
            
        }

        private List<FormSetScoringNo> ActionGetMarkableQuestions(FormGetMarkableQuestions pFormGetMarkableList)
        {
            
            //HttpRequestDictionary vFormParas = new HttpRequestDictionary();
            //vFormParas.Add("time", POSUtility.GetJSTime());
            //vFormParas.Add("testName", "予習シリーズ６年上　第２回");
            //vFormParas.Add("subjectName", "理科");
            //vFormParas.Add("courseName", "α");
            //vFormParas.Add("pageNum", "1");

            string tmplink = this.httpLink[PosLink.SELECTMARKABLEQUESTIONS];
            tmplink += "?";
            tmplink += pFormGetMarkableList.ToString();

            this.pHTMLDocument =
            this.phWebTools.HttpRequest(tmplink, new RequestHeaders());

            IHTMLElementCollection ihec =
            this.pHTMLDocument.getElementsByTagName("input");

            List<FormSetScoringNo> Lfssn = new List<FormSetScoringNo>();

            IHTMLElement ihe;
            //XmlDocument xd = new XmlDocument();
            //XmlAttribute xa;
            string tmpQuestionsNum = "";
            for (int i = 0; i < ihec.length; i++)
            {

                ihe = (IHTMLElement)ihec.item(i);
                Console.WriteLine(ihe.outerHTML);

                if (ihe.outerHTML.Contains("onclick=\"setQuestion("))
                {
                    //+sheetnum
                    IHTMLElementCollection tmpCollect =
                    (IHTMLElementCollection)ihe.parentElement.parentElement.children;
                    IHTMLElement tmpElement;
                    if (tmpCollect.length > 1)
                    {
                        tmpElement = (IHTMLElement)tmpCollect.item(1);
                        //tmpElement.children

                        tmpQuestionsNum =
                        tmpElement.innerText;
                    }
                    //-sheetnum


                    Lfssn.Add(new FormSetScoringNo(ihe.outerHTML, tmpQuestionsNum,this.testKouseiId));
                }

            }

            return Lfssn;
        
        }


        private void ActionPartialQuestionsLoad(FormSetScoringNo pFormSetScoringNo)
        {
             this.pHTMLDocument =
             this.phWebTools.SubmitFormData(this.httpLink[PosLink.PCPARTIALLIST], pFormSetScoringNo.ToString()); 
        

            //========================================
            //Answer
            //<img src='/MarkingSystemWeb/displayImage.do?imageType=clopAnswer&id=21' border='1' style='border-color: blue;' />
            
            //<input id="submitMarkBtn" align="right" type="button" name="submitMark" value='Mark Confirmed' style="height:50px;" onclick="javascript: submitToMarkAction()">
        
        

            //+JS:Submit
            //submitToMarkAction
            //checkMarkResult() = true;
            //comXml = buildCommentXml(xOriginOffset,yOriginOffset)
            //document.pcPartialMarkingForm.commentXml.value = (comXml.xml).replace("/(\r\n)+$/g",'');
            //-JS:Submit
        }
        private void ParsePartialXML()
        {

            IHTMLElementCollection ttt =
            (IHTMLElementCollection)this.pHTMLDocument.getElementsByName("request");
            IHTMLElement
            ihe =
            (IHTMLElement)ttt.item(0);
            //IHTMLElement tt = (IHTMLElement)ihfe.elements["request"];

            string reqXML = HttpUtility.UrlDecode(ihe.getAttribute("value").ToString());

            XmlDocument xd = new XmlDocument();
            xd.LoadXml(reqXML);
            XmlNodeList results = xd.GetElementsByTagName("markingPcPartial");

            if (results != null
                && results.Count > 0
                )
            {

                XmlNode nodeParent = results.Item(0);
                XmlNodeList childNodes = nodeParent.ChildNodes;

                string questionId = "";
                string allocatedPoint = "";

                List<FormMark> fmList = new List<FormMark>();

                for (int i = 0; i < childNodes.Count; i++)
                {
                    Console.Write(childNodes[i].Name);
                    if (childNodes[i].Name == "message")
                    {


                    }
                    else if (childNodes[i].Name == "questionId")
                    {
                        string unitNoMarking = childNodes[i].InnerText;
                        questionId = unitNoMarking;

                    }
                    else if (childNodes[i].Name == "allocatedPoint")
                    {
                        //	alert("childNode[" + i + "] " + childNodes[i].tagName + "=" + childNodes[i].childNodes[0].nodeValue);
                        allocatedPoint = childNodes[i].FirstChild.Value;

                    }
                    else if (childNodes[i].Name == "height")
                    {
                        //	alert("childNode[" + i + "] " + childNodes[i].tagName + "=" + childNodes[i].childNodes[0].nodeValue);
                        //CELL_HEIGHT = eval(childNodes[i].childNodes[0].nodeValue);

                    }
                    else if (childNodes[i].Name == "width")
                    {
                        //	alert("childNode[" + i + "] " + childNodes[i].tagName + "=" + childNodes[i].childNodes[0].nodeValue);
                        //CELL_WIDTH = eval(childNodes[i].childNodes[0].nodeValue);

                    }
                    else if (childNodes[i].Name == "markingImageGood")
                    {
                        //	alert("childNode[" + i + "] " + childNodes[i].tagName + "=" + childNodes[i].childNodes[0].nodeValue);
                        //IMAGE_MARKING_TOOL_GOOD = childNodes[i].childNodes[0].nodeValue;

                    }
                    else if (childNodes[i].Name == "markingImageBad")
                    {
                        //	alert("childNode[" + i + "] " + childNodes[i].tagName + "=" + childNodes[i].childNodes[0].nodeValue);
                        //IMAGE_MARKING_TOOL_BAD = childNodes[i].childNodes[0].nodeValue;
                    }
                    else if (childNodes[i].Name == "markingImagePartial")
                    {
                        //	alert("childNode[" + i + "] " + childNodes[i].tagName + "=" + childNodes[i].childNodes[0].nodeValue);
                        //IMAGE_MARKING_TOOL_PARTIAL_GOOD = childNodes[i].childNodes[0].nodeValue;
                    }
                    else if (childNodes[i].Name == "markingImageNone")
                    {
                        //	alert("childNode[" + i + "] " + childNodes[i].tagName + "=" + childNodes[i].childNodes[0].nodeValue);
                        //IMAGE_MARKING_TOOL_NO_ANSWER = childNodes[i].childNodes[0].nodeValue;
                    }
                    else if (childNodes[i].Name == "question")
                    {


                        var id = childNodes[i].Attributes["id"];
                        var regNo = childNodes[i].ChildNodes[0].FirstChild;
                        var image = childNodes[i].ChildNodes[1].FirstChild;
                        var studentNo = childNodes[i].ChildNodes[2].FirstChild;


                        fmList.Add(new FormMark(id.Value, questionId, regNo.Value, allocatedPoint, image.Value, studentNo.Value));
                        Console.WriteLine(" : " + id.Value);
                        Console.WriteLine(" : " + regNo.Value);
                        Console.WriteLine(" : " + image.Value);
                        Console.WriteLine(" : " + studentNo.Value);

                    }

                    if (childNodes[i].Name != "question")
                    {
                        Console.WriteLine(" : " + childNodes[i].InnerText);
                    }




                }
                string tmpStrJson = "'([";

                foreach (FormMark fm in fmList) {
                    tmpStrJson += fm.ToJson();
                    tmpStrJson += ",";
                }
                tmpStrJson = tmpStrJson.TrimEnd(',');
                tmpStrJson += "])'";

                /*marks:
                 * checkMarkResult 
                 * createImageFromObject
                 * redrawPartialPointArea
                 */
            }

            //Get Image OK
            //********* http://pos.toshin.com/MarkingSystemWeb/pcPartialImage.do?imgType=partial&imgRegNo=31223686&unitNo=21&&zoom=100
            //Get Image OK


            return;

            //Request URL:http://pos.toshin.com/MarkingSystemWeb/pcPartialList.do
            //Request Method:POST
            //request:INITIAL
            //requestPre:
            //response:
            //responsePre:
            //showAnswer:false
            //zoom:1.0 
            //$50%,100%,200%
            //canelForward:
            //commentXml:
            //testKouseiId:1264302
            //scoringNo:4
            //maxMarks:3
            //numberOfSet:50
            //mouseMarker:2
            //$1:O,2:X,3:P,4:NoAnswer,5:AbnormalData
            //var MODE_MARKING_NO_SELECT = 0;
            //var MODE_MARKING_GOOD = 1;
            //var MODE_MARKING_BAD = 2;
            //var MODE_MARKING_PARTIAL_GOOD = 3;
            //var MODE_MARKING_NO_ANSWER = 4;
            //var MODE_MARKING_ABNORMAL = 5;

            //req
            //<?xml version="1.0" encoding="UTF-8"?><markingPcPartial><message>PC分割採点</message><questionId>4</questionId><allocatedPoint>3</allocatedPoint><height>92</height><width>118</width><markingImageGood>parts/maru.png</markingImageGood><markingImageBad>parts/batsu.png</markingImageBad><markingImagePartial>parts/sankaku.png</markingImagePartial><markingImageNone>parts/mukaito.png</markingImageNone><question id="0"><paperRegNo>31172181</paperRegNo><image>pcPartialImage.do?imgType=partial&amp;imgRegNo=31172181&amp;unitNo=4</image><studentNo>1552431 </studentNo></question><question id="1"><paperRegNo>31173371</paperRegNo><image>pcPartialImage.do?imgType=partial&amp;imgRegNo=31173371&amp;unitNo=4</image><studentNo>7682841 </studentNo></question><question id="2"><paperRegNo>31171149</paperRegNo><image>pcPartialImage.do?imgType=partial&amp;imgRegNo=31171149&amp;unitNo=4</image><studentNo>1442546 </studentNo></question><question id="3"><paperRegNo>31169548</paperRegNo><image>pcPartialImage.do?imgType=partial&amp;imgRegNo=31169548&amp;unitNo=4</image><studentNo>1520725 </studentNo></question><question id="4"><paperRegNo>31170718</paperRegNo><image>pcPartialImage.do?imgType=partial&amp;imgRegNo=31170718&amp;unitNo=4</image><studentNo>1630768 </studentNo></question><question id="5"><paperRegNo>31173370</paperRegNo><image>pcPartialImage.do?imgType=partial&amp;imgRegNo=31173370&amp;unitNo=4</image><studentNo>1638572 </studentNo></question><question id="6"><paperRegNo>31171022</paperRegNo><image>pcPartialImage.do?imgType=partial&amp;imgRegNo=31171022&amp;unitNo=4</image><studentNo>1644033 </studentNo></question><question id="7"><paperRegNo>31170727</paperRegNo><image>pcPartialImage.do?imgType=partial&amp;imgRegNo=31170727&amp;unitNo=4</image><studentNo>1663682 </studentNo></question><question id="8"><paperRegNo>31170197</paperRegNo><image>pcPartialImage.do?imgType=partial&amp;imgRegNo=31170197&amp;unitNo=4</image><studentNo>1618474 </studentNo></question><question id="9"><paperRegNo>31171152</paperRegNo><image>pcPartialImage.do?imgType=partial&amp;imgRegNo=31171152&amp;unitNo=4</image><studentNo>1352555 </studentNo></question><question id="10"><paperRegNo>31168628</paperRegNo><image>pcPartialImage.do?imgType=partial&amp;imgRegNo=31168628&amp;unitNo=4</image><studentNo>1409557 </studentNo></question><question id="11"><paperRegNo>31171142</paperRegNo><image>pcPartialImage.do?imgType=partial&amp;imgRegNo=31171142&amp;unitNo=4</image><studentNo>1473450 </studentNo></question><question id="12"><paperRegNo>31168349</paperRegNo><image>pcPartialImage.do?imgType=partial&amp;imgRegNo=31168349&amp;unitNo=4</image><studentNo>1724851 </studentNo></question><question id="13"><paperRegNo>31168339</paperRegNo><image>pcPartialImage.do?imgType=partial&amp;imgRegNo=31168339&amp;unitNo=4</image><studentNo>1443232 </studentNo></question><question id="14"><paperRegNo>31171715</paperRegNo><image>pcPartialImage.do?imgType=partial&amp;imgRegNo=31171715&amp;unitNo=4</image><studentNo>1660225 </studentNo></question><question id="15"><paperRegNo>31169616</paperRegNo><image>pcPartialImage.do?imgType=partial&amp;imgRegNo=31169616&amp;unitNo=4</image><studentNo>1659537 </studentNo></question><question id="16"><paperRegNo>31171721</paperRegNo><image>pcPartialImage.do?imgType=partial&amp;imgRegNo=31171721&amp;unitNo=4</image><studentNo>1648705 </studentNo></question><question id="17"><paperRegNo>31169615</paperRegNo><image>pcPartialImage.do?imgType=partial&amp;imgRegNo=31169615&amp;unitNo=4</image><studentNo>1686909 </studentNo></question><question id="18"><paperRegNo>31173365</paperRegNo><image>pcPartialImage.do?imgType=partial&amp;imgRegNo=31173365&amp;unitNo=4</image><studentNo>1558676 </studentNo></question><question id="19"><paperRegNo>31168674</paperRegNo><image>pcPartialImage.do?imgType=partial&amp;imgRegNo=31168674&amp;unitNo=4</image><studentNo>1705547 </studentNo></question><question id="20"><paperRegNo>31168680</paperRegNo><image>pcPartialImage.do?imgType=partial&amp;imgRegNo=31168680&amp;unitNo=4</image><studentNo>1473760 </studentNo></question></markingPcPartial>
            //req0
            //<?xml+version="1.0"+encoding="UTF-8"?><markingPcPartial><message>PC分割採点</message><questionId>4</questionId><allocatedPoint>3</allocatedPoint><height>92</height><width>118</width><markingImageGood>parts/maru.png</markingImageGood><markingImageBad>parts/batsu.png</markingImageBad><markingImagePartial>parts/sankaku.png</markingImagePartial><markingImageNone>parts/mukaito.png</markingImageNone><question+id="0"><paperRegNo>31172181</paperRegNo><image>pcPartialImage.do?imgType=partial&amp;imgRegNo=31172181&amp;unitNo=4</image><studentNo>1552431+</studentNo></question><question+id="1"><paperRegNo>31173371</paperRegNo><image>pcPartialImage.do?imgType=partial&amp;imgRegNo=31173371&amp;unitNo=4</image><studentNo>7682841+</studentNo></question><question+id="2"><paperRegNo>31171149</paperRegNo><image>pcPartialImage.do?imgType=partial&amp;imgRegNo=31171149&amp;unitNo=4</image><studentNo>1442546+</studentNo></question><question+id="3"><paperRegNo>31169548</paperRegNo><image>pcPartialImage.do?imgType=partial&amp;imgRegNo=31169548&amp;unitNo=4</image><studentNo>1520725+</studentNo></question><question+id="4"><paperRegNo>31170718</paperRegNo><image>pcPartialImage.do?imgType=partial&amp;imgRegNo=31170718&amp;unitNo=4</image><studentNo>1630768+</studentNo></question><question+id="5"><paperRegNo>31173370</paperRegNo><image>pcPartialImage.do?imgType=partial&amp;imgRegNo=31173370&amp;unitNo=4</image><studentNo>1638572+</studentNo></question><question+id="6"><paperRegNo>31171022</paperRegNo><image>pcPartialImage.do?imgType=partial&amp;imgRegNo=31171022&amp;unitNo=4</image><studentNo>1644033+</studentNo></question><question+id="7"><paperRegNo>31170727</paperRegNo><image>pcPartialImage.do?imgType=partial&amp;imgRegNo=31170727&amp;unitNo=4</image><studentNo>1663682+</studentNo></question><question+id="8"><paperRegNo>31170197</paperRegNo><image>pcPartialImage.do?imgType=partial&amp;imgRegNo=31170197&amp;unitNo=4</image><studentNo>1618474+</studentNo></question><question+id="9"><paperRegNo>31171152</paperRegNo><image>pcPartialImage.do?imgType=partial&amp;imgRegNo=31171152&amp;unitNo=4</image><studentNo>1352555+</studentNo></question><question+id="10"><paperRegNo>31168628</paperRegNo><image>pcPartialImage.do?imgType=partial&amp;imgRegNo=31168628&amp;unitNo=4</image><studentNo>1409557+</studentNo></question><question+id="11"><paperRegNo>31171142</paperRegNo><image>pcPartialImage.do?imgType=partial&amp;imgRegNo=31171142&amp;unitNo=4</image><studentNo>1473450+</studentNo></question><question+id="12"><paperRegNo>31168349</paperRegNo><image>pcPartialImage.do?imgType=partial&amp;imgRegNo=31168349&amp;unitNo=4</image><studentNo>1724851+</studentNo></question><question+id="13"><paperRegNo>31168339</paperRegNo><image>pcPartialImage.do?imgType=partial&amp;imgRegNo=31168339&amp;unitNo=4</image><studentNo>1443232+</studentNo></question><question+id="14"><paperRegNo>31171715</paperRegNo><image>pcPartialImage.do?imgType=partial&amp;imgRegNo=31171715&amp;unitNo=4</image><studentNo>1660225+</studentNo></question><question+id="15"><paperRegNo>31169616</paperRegNo><image>pcPartialImage.do?imgType=partial&amp;imgRegNo=31169616&amp;unitNo=4</image><studentNo>1659537+</studentNo></question><question+id="16"><paperRegNo>31171721</paperRegNo><image>pcPartialImage.do?imgType=partial&amp;imgRegNo=31171721&amp;unitNo=4</image><studentNo>1648705+</studentNo></question><question+id="17"><paperRegNo>31169615</paperRegNo><image>pcPartialImage.do?imgType=partial&amp;imgRegNo=31169615&amp;unitNo=4</image><studentNo>1686909+</studentNo></question><question+id="18"><paperRegNo>31173365</paperRegNo><image>pcPartialImage.do?imgType=partial&amp;imgRegNo=31173365&amp;unitNo=4</image><studentNo>1558676+</studentNo></question><question+id="19"><paperRegNo>31168674</paperRegNo><image>pcPartialImage.do?imgType=partial&amp;imgRegNo=31168674&amp;unitNo=4</image><studentNo>1705547+</studentNo></question><question+id="20"><paperRegNo>31168680</paperRegNo><image>pcPartialImage.do?imgType=partial&amp;imgRegNo=31168680&amp;unitNo=4</image><studentNo>1473760+</studentNo></question></markingPcPartial>

            //<form name="pcPartialMarkingForm" method="post" action="/MarkingSystemWeb/pcPartialList.do" onsubmit="return false;">
            //<input type="hidden" name="request" value="%3C%3Fxml+version%3D%221.0%22+encoding%3D%22UTF-8%22%3F%3E%3CmarkingPcPartial%3E%3Cmessage%3EPC%E5%88%86%E5%89%B2%E6%8E%A1%E7%82%B9%3C%2Fmessage%3E%3CquestionId%3E4%3C%2FquestionId%3E%3CallocatedPoint%3E3%3C%2FallocatedPoint%3E%3Cheight%3E92%3C%2Fheight%3E%3Cwidth%3E118%3C%2Fwidth%3E%3CmarkingImageGood%3Eparts%2Fmaru.png%3C%2FmarkingImageGood%3E%3CmarkingImageBad%3Eparts%2Fbatsu.png%3C%2FmarkingImageBad%3E%3CmarkingImagePartial%3Eparts%2Fsankaku.png%3C%2FmarkingImagePartial%3E%3CmarkingImageNone%3Eparts%2Fmukaito.png%3C%2FmarkingImageNone%3E%3Cquestion+id%3D%220%22%3E%3CpaperRegNo%3E31172181%3C%2FpaperRegNo%3E%3Cimage%3EpcPartialImage.do%3FimgType%3Dpartial%26amp%3BimgRegNo%3D31172181%26amp%3BunitNo%3D4%3C%2Fimage%3E%3CstudentNo%3E1552431+%3C%2FstudentNo%3E%3C%2Fquestion%3E%3Cquestion+id%3D%221%22%3E%3CpaperRegNo%3E31173371%3C%2FpaperRegNo%3E%3Cimage%3EpcPartialImage.do%3FimgType%3Dpartial%26amp%3BimgRegNo%3D31173371%26amp%3BunitNo%3D4%3C%2Fimage%3E%3CstudentNo%3E7682841+%3C%2FstudentNo%3E%3C%2Fquestion%3E%3Cquestion+id%3D%222%22%3E%3CpaperRegNo%3E31171149%3C%2FpaperRegNo%3E%3Cimage%3EpcPartialImage.do%3FimgType%3Dpartial%26amp%3BimgRegNo%3D31171149%26amp%3BunitNo%3D4%3C%2Fimage%3E%3CstudentNo%3E1442546+%3C%2FstudentNo%3E%3C%2Fquestion%3E%3Cquestion+id%3D%223%22%3E%3CpaperRegNo%3E31169548%3C%2FpaperRegNo%3E%3Cimage%3EpcPartialImage.do%3FimgType%3Dpartial%26amp%3BimgRegNo%3D31169548%26amp%3BunitNo%3D4%3C%2Fimage%3E%3CstudentNo%3E1520725+%3C%2FstudentNo%3E%3C%2Fquestion%3E%3Cquestion+id%3D%224%22%3E%3CpaperRegNo%3E31170718%3C%2FpaperRegNo%3E%3Cimage%3EpcPartialImage.do%3FimgType%3Dpartial%26amp%3BimgRegNo%3D31170718%26amp%3BunitNo%3D4%3C%2Fimage%3E%3CstudentNo%3E1630768+%3C%2FstudentNo%3E%3C%2Fquestion%3E%3Cquestion+id%3D%225%22%3E%3CpaperRegNo%3E31173370%3C%2FpaperRegNo%3E%3Cimage%3EpcPartialImage.do%3FimgType%3Dpartial%26amp%3BimgRegNo%3D31173370%26amp%3BunitNo%3D4%3C%2Fimage%3E%3CstudentNo%3E1638572+%3C%2FstudentNo%3E%3C%2Fquestion%3E%3Cquestion+id%3D%226%22%3E%3CpaperRegNo%3E31171022%3C%2FpaperRegNo%3E%3Cimage%3EpcPartialImage.do%3FimgType%3Dpartial%26amp%3BimgRegNo%3D31171022%26amp%3BunitNo%3D4%3C%2Fimage%3E%3CstudentNo%3E1644033+%3C%2FstudentNo%3E%3C%2Fquestion%3E%3Cquestion+id%3D%227%22%3E%3CpaperRegNo%3E31170727%3C%2FpaperRegNo%3E%3Cimage%3EpcPartialImage.do%3FimgType%3Dpartial%26amp%3BimgRegNo%3D31170727%26amp%3BunitNo%3D4%3C%2Fimage%3E%3CstudentNo%3E1663682+%3C%2FstudentNo%3E%3C%2Fquestion%3E%3Cquestion+id%3D%228%22%3E%3CpaperRegNo%3E31170197%3C%2FpaperRegNo%3E%3Cimage%3EpcPartialImage.do%3FimgType%3Dpartial%26amp%3BimgRegNo%3D31170197%26amp%3BunitNo%3D4%3C%2Fimage%3E%3CstudentNo%3E1618474+%3C%2FstudentNo%3E%3C%2Fquestion%3E%3Cquestion+id%3D%229%22%3E%3CpaperRegNo%3E31171152%3C%2FpaperRegNo%3E%3Cimage%3EpcPartialImage.do%3FimgType%3Dpartial%26amp%3BimgRegNo%3D31171152%26amp%3BunitNo%3D4%3C%2Fimage%3E%3CstudentNo%3E1352555+%3C%2FstudentNo%3E%3C%2Fquestion%3E%3Cquestion+id%3D%2210%22%3E%3CpaperRegNo%3E31168628%3C%2FpaperRegNo%3E%3Cimage%3EpcPartialImage.do%3FimgType%3Dpartial%26amp%3BimgRegNo%3D31168628%26amp%3BunitNo%3D4%3C%2Fimage%3E%3CstudentNo%3E1409557+%3C%2FstudentNo%3E%3C%2Fquestion%3E%3Cquestion+id%3D%2211%22%3E%3CpaperRegNo%3E31171142%3C%2FpaperRegNo%3E%3Cimage%3EpcPartialImage.do%3FimgType%3Dpartial%26amp%3BimgRegNo%3D31171142%26amp%3BunitNo%3D4%3C%2Fimage%3E%3CstudentNo%3E1473450+%3C%2FstudentNo%3E%3C%2Fquestion%3E%3Cquestion+id%3D%2212%22%3E%3CpaperRegNo%3E31168349%3C%2FpaperRegNo%3E%3Cimage%3EpcPartialImage.do%3FimgType%3Dpartial%26amp%3BimgRegNo%3D31168349%26amp%3BunitNo%3D4%3C%2Fimage%3E%3CstudentNo%3E1724851+%3C%2FstudentNo%3E%3C%2Fquestion%3E%3Cquestion+id%3D%2213%22%3E%3CpaperRegNo%3E31168339%3C%2FpaperRegNo%3E%3Cimage%3EpcPartialImage.do%3FimgType%3Dpartial%26amp%3BimgRegNo%3D31168339%26amp%3BunitNo%3D4%3C%2Fimage%3E%3CstudentNo%3E1443232+%3C%2FstudentNo%3E%3C%2Fquestion%3E%3Cquestion+id%3D%2214%22%3E%3CpaperRegNo%3E31171715%3C%2FpaperRegNo%3E%3Cimage%3EpcPartialImage.do%3FimgType%3Dpartial%26amp%3BimgRegNo%3D31171715%26amp%3BunitNo%3D4%3C%2Fimage%3E%3CstudentNo%3E1660225+%3C%2FstudentNo%3E%3C%2Fquestion%3E%3Cquestion+id%3D%2215%22%3E%3CpaperRegNo%3E31169616%3C%2FpaperRegNo%3E%3Cimage%3EpcPartialImage.do%3FimgType%3Dpartial%26amp%3BimgRegNo%3D31169616%26amp%3BunitNo%3D4%3C%2Fimage%3E%3CstudentNo%3E1659537+%3C%2FstudentNo%3E%3C%2Fquestion%3E%3Cquestion+id%3D%2216%22%3E%3CpaperRegNo%3E31171721%3C%2FpaperRegNo%3E%3Cimage%3EpcPartialImage.do%3FimgType%3Dpartial%26amp%3BimgRegNo%3D31171721%26amp%3BunitNo%3D4%3C%2Fimage%3E%3CstudentNo%3E1648705+%3C%2FstudentNo%3E%3C%2Fquestion%3E%3Cquestion+id%3D%2217%22%3E%3CpaperRegNo%3E31169615%3C%2FpaperRegNo%3E%3Cimage%3EpcPartialImage.do%3FimgType%3Dpartial%26amp%3BimgRegNo%3D31169615%26amp%3BunitNo%3D4%3C%2Fimage%3E%3CstudentNo%3E1686909+%3C%2FstudentNo%3E%3C%2Fquestion%3E%3Cquestion+id%3D%2218%22%3E%3CpaperRegNo%3E31173365%3C%2FpaperRegNo%3E%3Cimage%3EpcPartialImage.do%3FimgType%3Dpartial%26amp%3BimgRegNo%3D31173365%26amp%3BunitNo%3D4%3C%2Fimage%3E%3CstudentNo%3E1558676+%3C%2FstudentNo%3E%3C%2Fquestion%3E%3Cquestion+id%3D%2219%22%3E%3CpaperRegNo%3E31168674%3C%2FpaperRegNo%3E%3Cimage%3EpcPartialImage.do%3FimgType%3Dpartial%26amp%3BimgRegNo%3D31168674%26amp%3BunitNo%3D4%3C%2Fimage%3E%3CstudentNo%3E1705547+%3C%2FstudentNo%3E%3C%2Fquestion%3E%3Cquestion+id%3D%2220%22%3E%3CpaperRegNo%3E31168680%3C%2FpaperRegNo%3E%3Cimage%3EpcPartialImage.do%3FimgType%3Dpartial%26amp%3BimgRegNo%3D31168680%26amp%3BunitNo%3D4%3C%2Fimage%3E%3CstudentNo%3E1473760+%3C%2FstudentNo%3E%3C%2Fquestion%3E%3C%2FmarkingPcPartial%3E">

            //mark = new Mark;
            //mark.index = id;
            //mark.questionId = questionId;
            //mark.paperRegNo = regNo;
            //mark.allocatedPoint = allocatedPoint;
            //mark.image = image;
            //mark.studentNo = studentNo;

            //createMarkingSpace

        }

        private void CheckLogin(){

            //Check
            //User ID/ Password is not correct. Reconfirm the Input User ID/ Password.
            IHTMLElement ihe;
                ihe = this.pHTMLDocument.getElementById("lblErrorMessage");

            if (ihe != null)
            {
                //need ? ihe.innerText != "" ;
                throw new PosContentException(ihe.innerText);
            }
        
        }

        private string GetElementById(string itemName,string attName){

            IHTMLElement ihe = null;
            string res = "";

            ihe =
            this.pHTMLDocument.getElementById(itemName); //id Dunplicate Exceotion

            if(ihe == null){
                throw new PosContentException(String.Format(""));//?
            }

            res = 
            ihe.getAttribute(attName).ToString();

            return res;
        }

        private bool CheckSetCourse() {
            IHTMLElement ihte;
            
            IHTMLElementCollection hec =
             (IHTMLElementCollection)this.pHTMLDocument.getElementsByTagName("a");

            if (hec.length == 0)
            {

            }
            else { 
                for(int i = 0 ; i<hec.length;i++){
                    ihte=
                    (IHTMLElement)hec.item(i);
                    if ("PC Marking".Equals(ihte.innerText.Trim()) || "PC採点".Equals(ihte.innerText.Trim()))
                    {
                        return true;
                    }
                    if ("PC Partial Marking".Equals(ihte.innerText.Trim()) || "PC分割採点".Equals(ihte.innerText.Trim()))
                    {
                        return true;
                    }
                }

            }

            return false;

        }

        private void CheckRequest() {

            //Exception
            if (this.pHTMLDocument == null)
            {
                throw new PosException.PosHttpException();
            }   
        }

        private bool CheckAuthorization() {

            //認証エラー
            if ("認証エラー".EndsWith(this.pHTMLDocument.title))
            {
                IHTMLFormElement ihfe = (IHTMLFormElement)this.pHTMLDocument.forms.item(0);
                if("UnAuthorizedMenu.aspx".EndsWith(ihfe.action)){
                    return true;
                }

                //有効な認証情報が取得できませんでした。
                //<a href="../SSOLogin/">≫こちら</a>からログインしなおしてください。
            }

            //Error
            if ("Error".EndsWith(this.pHTMLDocument.title))
            {
                //IHTMLFormElement ihfe = (IHTMLFormElement)this.pHTMLDocument.forms.item(0);
                //if ("UnAuthorizedMenu.aspx".EndsWith(ihfe.action))
                //{
                //    return true;
                //}

                //Please call an administrator.
                //Could not find authentication. Please login again from SSO menu.

                return false;
            }

            return false;
            
        }

        
    }
}
